package gdconf

import (
	"server_cluster/common/logger"
)

// 家园等级配置表

type HomeLevelConfig struct {
	Level int32 `csv:"HomeLevel" gorm:"primary_key;autoIncrement:false"` // 等级
	Exp   int32 `csv:"Prosperity,omitempty"`                             // 升到下一等级所需经验
}

func (h *HomeLevelConfig) TableName() string {
	return "config_home_level"
}

func (g *GameDataConfig) saveHomeLevelConfig() {
	saveTableToDb[HomeLevelConfig](g.Db, readTable[HomeLevelConfig](g.CsvPathPrefix+"HomeLevel.csv"))
}

func (g *GameDataConfig) loadHomeLevelConfig() {
	g.GameDataMaps.HomeLevelConfigMap = make(map[int32]*HomeLevelConfig)
	for _, homeLevelConfig := range loadTableFromDb[HomeLevelConfig](g.Db) {
		g.GameDataMaps.HomeLevelConfigMap[homeLevelConfig.Level] = homeLevelConfig
	}
	logger.Info("HomeLevelConfig Count: %v", len(g.GameDataMaps.HomeLevelConfigMap))
}

func GetHomeLevelConfig(buildingId int32) *HomeLevelConfig {
	value, exist := CONF.GameDataMaps.HomeLevelConfigMap[buildingId]
	if !exist {
		logger.Error("[ConfigNotFound] HomeLevelConfig, buildingId: %v", buildingId)
		return nil
	}
	return value
}

func GetHomeLevelConfigMap() map[int32]*HomeLevelConfig {
	return CONF.GameDataMaps.HomeLevelConfigMap
}
